<?php

namespace App\Http\Controllers\Admin\Tag;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Http\Model\Tags;
class TagController extends Controller
{
    //标签列表

    public function tagList()
    {
        $res = Tags::select()->paginate(10);
        $popular_tagname = request('search');
        if (!empty($popular_tagname)){
           $res = Tags::where('popular_tagname', 'like', "%{$popular_tagname}%")->paginate(10);
        }
        return view('Admin/Tag/tag_lists')->with('res',$res);
    }

   // 添加标签

    public function add_tag(Request $request)
    {
        if ($request->isMethod('get')) {

            return view('Admin/Tag/add_tag');
        }
        if ($request->isMethod('post')) {
            $popular_tagname = request('popular_tagname');
            $url = request('url');
            $result = Tags::create(['popular_tagname' => $popular_tagname, 'url' => $url]);
            if ($result) {
                return response()->json(['status' => 200, 'message' => 'success']);
            } else {
                return response()->json(['status' => 200, 'message' => 'fail']);
            }
        }

    }

    // 删除标签
    public function tag_del($id)
    {
        return $res = Tags::where(['id'=>$id])->delete();

    }


}
